require 'remote_agent'
require 'remote_file'
require 'tag'
class ServerInterface
  def initialize(server)
    @server = server
  end

  def register(host, port)
    agent = RemoteAgent.new(:host => host, :port => port)
    agent.save
  end

  def publish(shared_file, host)
    agent = RemoteAgent.find_by_host(host)
    raise "#{host} is not a registered host" if agent.nil?
    remote_file = RemoteFile.new(:path => shared_file.path,
      :content => shared_file.content, :remote_agent => agent)
    remote_file.save
    shared_file.tags.each { |tag| remote_file.tags << Tag.new(:name => tag) } if shared_file.tags
  end
end
